package com.yvon.maple.service.system;

import java.util.Scanner;

public class T3 {


    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String a = scanner.nextLine();
        String[] arr = a.split(" ");
        int num = 0;
        int start =  Integer.parseInt(arr[0]);
        int end = Integer.parseInt(arr[1]);
        for (int i = start; i <= end; i++) {
            if (cn(i) && fn(i)) {
                num ++;
            }
        }

        System.out.println(num);



    }
    public static boolean fn(int a) {
        StringBuffer str = new StringBuffer();
        str.append(a);
        String a1 = str.toString();
        StringBuffer strRe = str.reverse();
        return strRe.toString().equals(a1);
    }

    public static boolean cn(int a) {
        if (a == 1 || a == 2) {
            return true;
        }
        boolean flag = true;
        for (int i = 2; i < a/2; i++) {
            if (a % i == 0) {
                flag  = false;
            }
        }
        return flag;
    }
}
